package com.guigu.tms.customer.controller;

import com.guigu.tms.commons.order.entity.Order;
import com.guigu.tms.commons.order.entity.vo.Result;
import com.guigu.tms.commons.order.feign.OrderFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderFeignClient orderFeignClient;

    @Autowired
    com.guigu.tms.commons.aggregation.feign.OrderFeignClient orderFeignClient1;

    //下单
    @PostMapping("createOrder")
    public boolean createOrder(@RequestBody Order order){
        return orderFeignClient.createOrder(order);
    }

    //修改订单
    @PutMapping("updateOrder/{orderId}")
    public Result updateOrder(@RequestBody Order order, @PathVariable("orderId") String OrderId){
        return orderFeignClient.updateOrder(order, OrderId);
    }

    //取消订单
    @PutMapping("cancelOrder/{orderId}")
    public Result cancelOrder(@PathVariable("orderId") String orderId,String cases){
        return orderFeignClient.cancelOrder(orderId,cases);
    }

    //查询订单
    @GetMapping("getOrders")
    public List<Order> getOrders(String memberId,String phone,Integer type){
        if(type.equals(1)){
            return orderFeignClient.getOrdersByMemberId(memberId);
        }
        return orderFeignClient.getOrdersByMobile(phone);
    }

    @GetMapping("getOrderDetails/{orderId}")
    public Order getOrderDetails(@PathVariable("orderId") String orderId){
        return orderFeignClient.getOrderDetails(orderId);
    }

    //获取订单预估价格
    @PostMapping("getOrderPrice")
    public String getOrderPrice(@RequestBody Order order){
        return orderFeignClient.getOrderPrice(order);
    }

    @GetMapping("getOrderById")
    public com.guigu.tms.commons.aggregation.entity.Order getOrderById(String id){
        return orderFeignClient1.getOrderById(id);
    }

}
